package com.amsp.oa.oademo.controller;

import com.amsp.oa.oademo.entity.FileDestruction;
import com.amsp.oa.oademo.service.FileDestructionService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "文件销毁申请单管理")
@RestController
@RequestMapping("/api/file-destruction")
public class FileDestructionController {

    @Autowired
    private FileDestructionService fileDestructionService;

    @ApiOperation("保存或更新文件销毁申请单")
    @PostMapping("/save")
    public boolean save(@RequestBody FileDestruction fileDestruction) {
        return fileDestructionService.saveOrUpdateWithDetails(fileDestruction);
    }

    @ApiOperation("分页查询文件销毁申请单")
    @GetMapping("/page")
    public IPage<FileDestruction> page(
            @ApiParam("当前页") @RequestParam(defaultValue = "1") Long current,
            @ApiParam("每页大小") @RequestParam(defaultValue = "10") Long size,
            @ApiParam("关键字") @RequestParam(required = false) String keyword) {
        return fileDestructionService.pageWithDetails(current, size, keyword);
    }

    @ApiOperation("获取文件销毁申请单详情")
    @GetMapping("/{id}")
    public FileDestruction getById(@PathVariable Long id) {
        return fileDestructionService.getWithDetails(id);
    }

    @ApiOperation("删除文件销毁申请单")
    @DeleteMapping("/{id}")
    public boolean removeById(@PathVariable Long id) {
        return fileDestructionService.removeById(id);
    }
}